package com.ruoyi.loan.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.TbCategoriesIdVo;
import com.ruoyi.common.core.domain.TbCategoriesVo;
import com.ruoyi.loan.product.domain.TbCategories;
import com.ruoyi.loan.product.domain.TbLoanProducts;
import com.ruoyi.loan.product.mapper.TbCategoriesMapper;
import com.ruoyi.loan.product.service.TbCategoriesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class TbCategoriesServiceImpl extends ServiceImpl<TbCategoriesMapper, TbCategories>
    implements TbCategoriesService {

    @Resource
    TbCategoriesMapper tbCategoriesMapper;

    @Override
    public R add(TbCategories categories) {
        try {
            tbCategoriesMapper.insert(categories);
            return R.ok(categories,"添加成功");
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return R.fail("添加失败");
    }

    @Override
    public R updateByCategories(TbCategories categories) {
        try {
            updateById(categories);
            return R.ok(categories,"修改成功");
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return R.fail("修改失败");
    }

    @Override
    public R deleteById(TbCategoriesIdVo tbCategoriesIdVo) {

        try {
            tbCategoriesMapper.deleteById(tbCategoriesIdVo.getCategoriesId());
            return R.ok(tbCategoriesIdVo,"删除成功");
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return R.fail("删除失败");
    }

    @Override
    public List<TbCategories> findAll(TbCategoriesVo categoriesVo) {
        QueryWrapper<TbCategories> queryWrapper = new QueryWrapper<>();
        List<TbCategories> list = tbCategoriesMapper.selectList(queryWrapper);
        return list;
    }
}




